package com.example.demo.web.config;

import com.example.demo.web.interceptor.TokenInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    private final Logger logger = LoggerFactory.getLogger(WebConfig.class);
    @Autowired
    private TokenInterceptor tokenInterceptor ;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        logger.info("添加token拦截器");
        registry.addInterceptor(tokenInterceptor).addPathPatterns("/**");

//        WebMvcConfigurer.super.addInterceptors(registry);
    }
    
    @Override
    public void addCorsMappings(CorsRegistry registry) {
    	logger.info("cors设置");
    	registry.addMapping("/**")
		.allowedOriginPatterns("*")
        .allowedHeaders("*")
        .allowedMethods("*")
        .maxAge(30*1000L);
    }
}
